package com.hkbigdata.springbootdi.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.hkbigdata.springbootdi.bean.OrderStatus;
import com.hkbigdata.springbootdi.bean.ProvinceData;
import com.hkbigdata.springbootdi.bean.SaleBrand;
import com.hkbigdata.springbootdi.bean.SaleBrandTotal;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author liuanbo
 * @creat 2024-12-06-10:55
 * @see 2194550857@qq.com
 */
@Mapper
@DS("mysql")
public interface DiMapper {

    @Select("select" +
            "    date_format(dt,'%H:%i') as `time`," +
            "    sum(orderCount) AS  orderConut," +
            "    sum(refundCount) AS  refundConut" +
            "    from Mybatis_225.di" +
            "    where DATE(dt)= #{dt}" +
            " group by date_format(dt,'%H:%i')" +
            " order by `time` asc;")
    List<OrderStatus> queryOrderStatus(@Param("dt") String dt);  // 查询订单状态

    @DS("ck")
    @Select("select" +
            "    brand as brand," +
            "    sum(saleAmount) as amount" +
            " from di" +
            " where toDate(dt) = today()" +
            " group by brand;")
    List<SaleBrand> querySaleBrand();  // 查询销售品牌

    @DS("ck")
    @Select("select" +
            "    a.brand as brand," +
            "    a.todayamount as todayamount," +
            "    b.yestodayamount as yestodayamount," +
            "    c.passweekamount as passweekamount" +
            "    from (select" +
            "              brand," +
            "              sum(saleAmount) as todayamount" +
            "          from di" +
            "          where toDate(dt) = today()" +
            "          group by brand) as a" +
            " full join (select" +
            "               brand," +
            "               sum(saleAmount) as yestodayamount" +
            "           from di" +
            "           where toDate(dt) = today()-1" +
            "           group by brand) as b" +
            " on a.brand=b.brand" +
            " full join (select" +
            "               brand," +
            "               sum(saleAmount) as passweekamount" +
            "           from di" +
            "           where toDate(dt) = today()-7" +
            "           group by brand) as c" +
            " on a.brand=c.brand;")
    List<SaleBrandTotal> querySaleBrandTotal();  // 查询销售品牌总表

    @DS("ck")
    @Select("select sum(saleamount) as amount" +
            " from ditohbase" +
            " where province = #{province} and toDate(saletime)= today();")
    Double querySaleAmount(@Param("province") String province );  // 查询销售总额

    @DS("ck")
    @Select("select " +
            "    province as name ," +
            "    sum(orderCount) as value," +
            "    sum(saleamount) as  sizeValue" +
            "    from ditohbase" +
            "   where toDate(dt)=today()" +
            " group by  province;")
    List<ProvinceData> queryProvinceData();  // 查询省份数据


}
